<#assign crudUrl="crud.ftl" />
<#assign crudJsonUrl="crud.json" />
<#assign beginPath="/dytemplate/crud/" />

<#macro body title="" encoding="utf-8" beginPath="/dytemplate/crud/">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=${encoding}">
<!-- crud js related -->
<!-- jquery js related -->
<script type="text/javascript" src="${beginPath}js/crud.valid.js"></script>
<script type="text/javascript" src="${beginPath}js/jquery.js"></script>
<script type="text/javascript" src="${beginPath}js/commons.js"></script>
<script type="text/javascript" src="${beginPath}js/niceforms.js"></script>
<#if ext_js_list?exists>
<#list ext_js_list as ext_js_file>
<script type="text/javascript" src="${beginPath}js/${ext_js_file}"></script>
</#list>
</#if>

<#if ext_css_list?exists>
<#list ext_css_list as ext_css_file>
<link href="${beginPath}css/${ext_css_file}" rel="stylesheet" type="text/css" />
</#list>
</#if>
<!-- css related -->
<link href="${beginPath}css/niceforms-default.css" rel="stylesheet" type="text/css" />
<link href="${beginPath}css/pager.css" rel="stylesheet" type="text/css" />

<link href="${beginPath}css/crud.css" rel="stylesheet" type="text/css" />

<title>${title?if_exists}</title>

	<script type="text/javascript">
	$(document).ready(function () {
		// nice forms
		init_niceform();
		
		<#if datagrid?exists && datagrid != "">
		$('#${datagrid}').flexigrid({
			height:'auto',
			striped:false,
			title:'${datagrid_title?if_exists}'
			});
		</#if>
		
		<#if datepiker_list?exists>
		<#list datepiker_list as datepiker>
		$('#${datepiker}').datepicker();
		</#list>
		</#if>
	});
	</script>
</head>

<body>

<@crud_nav />

<#nested>

</body>
</html>
</#macro>
<#-- End Crud Macro: Page -->

<#macro pagination style="scott" totalCount=8>
<#if page?exists>
<#assign cp = page.currentPage />
<#assign npp = page.numPerPage />

<#assign begin = cp - totalCount/2 />

<#assign totalRows = page.totalRows />
<#assign totalPages = page.getTotalPages() />

<#assign targetUrl = "#?1=1&" />
<#if req_url?exists>
	<#assign targetUrl = req_url />
</#if>

<div class="${style}">
	<span class="one">
	${locale.t_row_label?if_exists}:${totalRows}
	</span>
	<span class="one">
	${locale.t_page_label?if_exists}:${totalPages}
	</span>
	<#if (totalPages != 1)>
	<span class=""> 
		<a href="${targetUrl}&cp=1" title="First Page"><<</a>
	</span>
	</#if>
	
	<#assign count = 0 />
	<#list begin..totalPages as pp>
		<#if (begin <= 0)>
			<#assign begin = begin + 1 />
		<#else>
			<#if (count == totalCount)>
				<#break>
			<#else>
				<#if begin == cp>
					<span class="current" title="Current Page">${cp}</span>
				<#else>
					<a href="${targetUrl}&cp=${begin}&npp=${npp}" title="Page ${begin}">${begin}</a>
				</#if>
				<#assign begin = begin + 1 />
				<#assign count = count + 1 />
			</#if>
		</#if>
	</#list>
	<#if (totalPages > totalCount)>
	...
		<#if (cp == totalPages)>
			<span class="current" title="Current Page">${cp}</span>
		<#else>
			<a href="${targetUrl}&cp=${totalPages}&npp=${npp}" title="Last Page">${totalPages}</a>
		</#if>
	
		<#if cp != totalPages>
			<a href="${targetUrl}&cp=${cp + 1}&npp=${npp}" title="Next Page"> > </a>
		<#else>
			<a href="${targetUrl}&cp=${cp}&npp=${npp}" title="Next Page"> > </a>
		</#if>
	</#if>
	<select name="pager_npp" onchange="javascript:location.href='${targetUrl}&npp=' + this.value;">
		<option value="10">--</option>
		<option value="5">5</option>
		<option value="10">10</option>
		<option value="15">15</option>
		<option value="20">20</option>
	</select>
</div>
</#if>
</#macro>
<#-- End Crud Macro: Pagination -->

<#macro crud_nav style="default">

<div class="crud_nav_div">
<span>
<a href="#" onclick="javascript:history.go(-1);" title="${locale.back_opt?if_exists}"><img width="18px" height="18px" src="${crud.beginPath}images/opt/previous.gif" /></a>
</span>
<span>
<a href="${crudUrl}?model=${model_crud_url?if_exists}&opt=list" title="${locale.view_label?if_exists}"><img width="18px" height="18px" src="${crud.beginPath}images/opt/home.gif" /></a>
</span>
<span>
<a href="${crudUrl}?model=${model_crud_url?if_exists}&opt=listinpage" title="${locale.view_in_page_label?if_exists}"><img width="18px" height="18px" src="${crud.beginPath}images/opt/view.gif" /></a>
</span>
<span>
<a href="${crudUrl}?model=${model_crud_url?if_exists}&opt=addform" title="${locale.add_record_legend?if_exists}"><img width="18px" height="18px" src="${crud.beginPath}images/opt/add.gif" /></a>
</span>

<span>
<a href="${crudUrl}?model=${model_crud_url?if_exists}&opt=searchform" title="${locale.search_label?if_exists}"><img width="18px" height="18px" src="${crud.beginPath}images/opt/search.gif" /></a>
</span>

<span>
<a href="${crudUrl}?model=${model_crud_url?if_exists}&opt=exportpdf" title="${locale.export_pdf_label?if_exists}"><img width="18px" height="18px" src="${crud.beginPath}images/opt/pdf.gif" /></a>
</span>

<span>
<a href="${crudUrl}?model=${model_crud_url?if_exists}&opt=exportexcel" title="${locale.export_excel_label?if_exists}"><img width="18px" height="18px" src="${crud.beginPath}images/opt/excel.gif" /></a>
</span>

<#if (is_next?exists && is_next)>
<span>
<a href="${crudUrl}?model=${model_crud_url?if_exists}&opt=next" title="${locale.export_pdf_label?if_exists}"><img width="18px" height="18px" src="${crud.beginPath}images/opt/pdf.gif" /></a>
</span>

<span>
<a href="${crudUrl}?model=${model_crud_url?if_exists}&opt=pre" title="${locale.export_excel_label?if_exists}"><img width="18px" height="18px" src="${crud.beginPath}images/opt/excel.gif" /></a>
</span>
</#if>
</div>
</#macro>
<#-- End Crud Macro: Navigation -->